package nc.bs.test.bookdoc.rule;

import nc.impl.pubapp.pattern.rule.IRule;
import nc.vo.bd.meta.BatchOperateVO;
import nc.vo.pubapp.AppContext;
import nc.vo.test.bookdoc.BookdocVO;

public class DefaultValueRule implements IRule<BatchOperateVO>{

	@Override
	public void process(BatchOperateVO[] batchVOs) {
		
		if(batchVOs != null){
			for(BatchOperateVO batchVO : batchVOs){
				processSingle(batchVO);
			}
		}
		
		
	}

	private void processSingle(BatchOperateVO batchVO) {
		
		Object[] addObjs = batchVO.getAddObjs();
		
		Object[] uptObjs = batchVO.getUpdObjs();
		
		processAdd(addObjs);
		
		processUpt(uptObjs);
		
	}

	private void processUpt(Object[] uptObjs) {
		if(uptObjs != null){
			for(Object uptObj : uptObjs){
				BookdocVO vo = (BookdocVO) uptObj;
				
				vo.setModifier(AppContext.getInstance().getPkUser());
				vo.setModifiedtime(AppContext.getInstance().getServerTime());
			}
		}
	}

	private void processAdd(Object[] addObjs) {
		if(addObjs != null){
			for(Object addObj : addObjs){
				BookdocVO vo = (BookdocVO) addObj;
				
				vo.setAttributeValue("creator", AppContext.getInstance().getPkUser());
				vo.setCreationtime(AppContext.getInstance().getServerTime());
			}
		}
	}

}
